﻿using System.ComponentModel;
using System.ServiceModel.Activation;
using UFIDA.U9.WSS.DebugService.Debug;
using UFIDA.U9.WSS.DebugService.Interfaces;
using UFIDA.U9.WSS.ProxyService.Models;

namespace UFIDA.U9.WSS.DebugService.Services
{
    /// <summary>
    ///     调试服务
    /// </summary>
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class DebugService : IDebugService
    {
        /// <summary>
        ///     测试连接
        /// </summary>
        /// <returns></returns>
        [Description("测试连接")]
        public ReturnMessage<bool> TestConnection()
        {
            ReturnMessage<bool> ret = new ReturnMessage<bool>();
            ret.Data = true;
            return ret;
        }

        #region 事务调试

        [Description("是否事务调试中")]
        public ReturnMessage<bool> IsTransactionDebugging(int debugType, string proxyType)
        {
            ReturnMessage<bool> ret = new ReturnMessage<bool>();
            ret.Data = TransactionDebug.Instance.IsDebugging(debugType, proxyType);
            return ret;
        }

        [Description("启用事务调试")]
        public ReturnMessage<bool> SetupTransactionDebug(int debugType, string proxyType)
        {
            ReturnMessage<bool> ret = new ReturnMessage<bool>();
            ret.Data = TransactionDebug.Instance.Setup(debugType, proxyType);
            return ret;
        }

        [Description("停止事务调试")]
        public ReturnMessage<bool> StopTransactionDebug(int debugType, string proxyType)
        {
            ReturnMessage<bool> ret = new ReturnMessage<bool>();
            ret.Data = TransactionDebug.Instance.Stop(debugType, proxyType);
            return ret;
        }

        [Description("停止所有事务调试")]
        public ReturnMessage<bool> StopAllTransactionDebug()
        {
            ReturnMessage<bool> ret = new ReturnMessage<bool>();
            ret.Data = TransactionDebug.Instance.StopAll();
            return ret;
        }

        #endregion

        #region 代理调试

        [Description("是否代理Do调试中")]
        public ReturnMessage<bool> IsProxyDoDebugging(string proxyType)
        {
            ReturnMessage<bool> ret = new ReturnMessage<bool>();
            ret.Data = ProxyDoDebug.IsDebugging(proxyType);
            return ret;
        }

        [Description("启用代理Do调试")]
        public ReturnMessage<bool> SetupProxyDoDebug(string proxyType)
        {
            ReturnMessage<bool> ret = new ReturnMessage<bool>();
            ret.Data = ProxyDoDebug.Setup(proxyType);
            return ret;
        }

        [Description("停止代理Do调试")]
        public ReturnMessage<bool> StopProxyDoDebug(string proxyType)
        {
            ReturnMessage<bool> ret = new ReturnMessage<bool>();
            ret.Data = ProxyDoDebug.Stop(proxyType);
            return ret;
        }

        [Description("停止所有代理Do调试")]
        public ReturnMessage<bool> StopAllProxyDoDebug()
        {
            ReturnMessage<bool> ret = new ReturnMessage<bool>();
            ret.Data = ProxyDoDebug.StopAll();
            return ret;
        }

        #endregion
    }
}